package com.kyl.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.kyl.dto.NursingProjectPlanDto;
import com.kyl.entity.NursingProjectPlan;
import com.kyl.mapper.NursingPlanProjectMapper;
import com.kyl.service.NursingPlanProjectService;
import com.kyl.vo.NursingProjectPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @title NursingProjectPlanServiceImpl
 * @description 
 * @author WanJl
 * @version 1.0
 * @create 2025/1/17
 */
@Service
public class NursingPlanProjectServiceImpl implements NursingPlanProjectService {

    @Autowired
    private NursingPlanProjectMapper nursingPlanProjectMapper;

    @Autowired
    public NursingPlanProjectServiceImpl(NursingPlanProjectMapper nursingPlanProjectMapper) {
        this.nursingPlanProjectMapper = nursingPlanProjectMapper;
    }


    @Override
    public int add(NursingProjectPlanDto nursingProjectPlan) {
        NursingProjectPlan projectPlan = BeanUtil.toBean(nursingProjectPlan, NursingProjectPlan.class);
        return nursingPlanProjectMapper.insert(projectPlan);
    }

    @Override
    public int update(NursingProjectPlanDto nursingProjectPlan) {
        NursingProjectPlan projectPlan = BeanUtil.toBean(nursingProjectPlan, NursingProjectPlan.class);
        return nursingPlanProjectMapper.update(projectPlan);
    }

    @Override
    public int deleteByIds(List<Long> ids) {
        return nursingPlanProjectMapper.deleteByIds(ids);
    }

    @Override
    public NursingProjectPlanVo getById(Long id) {
        NursingProjectPlan byId = nursingPlanProjectMapper.getById(id);
        return BeanUtil.toBean(byId, NursingProjectPlanVo.class);
    }

    @Override
    public int addList(List<NursingProjectPlanDto> projectPlans) {
        List<NursingProjectPlan> projectPlanList = projectPlans.stream().map(v -> BeanUtil.toBean(v, NursingProjectPlan.class)).collect(Collectors.toList());
        return nursingPlanProjectMapper.insertList(projectPlanList);
    }
}
